import os
import subprocess
import uiautomation
import time
subprocess.Popen('calc.exe')
time.sleep(2)

wc =uiautomation.WindowControl(searchDepth= 1,ClassName='ApplicationFrameWindow',Name='计算器' )

# wc=wc.WindowControl(ClassName='ApplicationFrameWindow')

#设置为顶层
wc.SetTopmost(True)
wc.ButtonControl(Name='六').Click()
wc.ButtonControl(Name='加').Click()
wc.ButtonControl(Name='六').Click()
wc.ButtonControl(Name='等于').Click()
# 获取元素某标签的具体标签内容
result=wc.TextControl(AutomationId='CalculatorResults')
print(result.Name)
print(result.ClassName)
print(result.ProcessId)
print(result.AutomationId)
print(result.Culture)
print(result.ControlType)

if result.Name=='显示为 12':
    print('测试成功success')
else:
    print('测试失败error')
#进行截图
wc.CaptureToImage('test.png')
time.sleep(2)
wc.ButtonControl(Name='关闭 计算器').Click() #name可能会有变化，具体情况按照上面打印的Name进行填写
os.system("taskkill /F /IM calc.exe")
